package game.entity;

import java.awt.Graphics;
import java.util.regex.Pattern;

import applet.resource.Sprite0D;

import game.Entity;
import game.interfaces.Visible;
import game.room.Cell;
import game.room.Room;

/** All treasure objects MUST extend this class. */
public abstract class Treasure extends Entity implements Visible {
	/** @return the amount of points this treasure is worth. */
	public abstract int getValue();

	/** @return the sprite for this treasure. */
	public abstract Sprite0D getSprite();

	/** */
	private int x;
	/** */
	private int y;

	/**
	 * @param layer - the layer.
	 * @param row - the row.
	 * @param column - the column.
	 */
	public final void setPosition(final int layer, final int row,
		final int column) {
		x = column * Cell.WIDTH - Cell.WIDTH / 2;
		y = row * Cell.HEIGHT - (1 + layer) * Cell.HEIGHT / 2;
	}

	@Override
	public final void draw(final Graphics g) {
		getSprite().draw(g, x, y);
	}

	@Override
	public final boolean validatePosition(final Room room, final int layer,
		final int row, final int col) {
		return Pattern.compile("[WT]").matcher(
			room.getTerrainString(layer - 1, row, col, layer - 1, row, col))
			.find();
	}
}
